const state = {
  todoUndone: [],
  todoDone: [],
  todoSelected: {},
  page_type_of_S_inputTodo: null, // 0为新增待办，1为未完成待办，2为已完成待办
  page_title_of_S_inputTodo: '',
  readonly: false,  // 控制分类、标题、详情能否被更改
  showConfirm: false, // 控制是否显示保存修改按钮
  isPush: false,  // 控制是否显示确认完成按钮（点击后会向导师推送完成此待办的信息）
  isUnconfirm: false, // 控制是否显示撤销操作按钮
  isDelete: true, // 控制是否显示删除待办按钮
}

const getters = {}

const actions = {
  setTodoUndone (context, todoUndone) {
    context.commit('stageTodoUndone', todoUndone)
  },
  setTodoDone (context, todoDone) {
    context.commit('stageTodoDone', todoDone)
  },
  setTodoSelected (context, todoSelected) {
    context.commit('stageTodoSelected', todoSelected)
  },
  init_page_view (context, pageType) {  // 根据pageType初始化S_inputTodo页面上的文本和按钮
    context.commit('stagePageType', pageType)
    context.commit('val_of_params_in_s_inputTodo', pageType)
  }
}

const mutations = {
  stageTodoUndone (state, todoUndone) {
    state.todoUndone = todoUndone
  },
  stageTodoDone (state, todoDone) {
    state.todoDone = todoDone
  },
  stageTodoSelected (state, todoSelected) {
    state.todoSelected = todoSelected
  },
  stagePageType (state, pageType) {
    state.page_type_of_S_inputTodo = pageType
  },
  stagePageTitle (state, pageTitle) {
    state.page_title_of_S_inputTodo = pageTitle
  },
  val_of_params_in_s_inputTodo (state, pageType) {
    if (0 === pageType) {
      state.readonly = false
      state.showConfirm = true
      state.isPush = false
      state.isUnconfirm = false
      state.isDelete = false
      state.page_title_of_S_inputTodo = '新增待办'
    } else if (1 === pageType) {
      state.readonly = false
      state.showConfirm = true
      state.isPush = true
      state.isUnconfirm = false
      state.isDelete = true
      state.page_title_of_S_inputTodo = '待办详情'
    } else {
      state.readonly = true
      state.showConfirm = false
      state.isPush = false
      state.isUnconfirm = true
      state.isDelete = true
      state.page_title_of_S_inputTodo = '待办详情'
    }
  }
}

export default {
  namespaced: true,
  state,
  getters,
  actions,
  mutations
}